#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
    clock_t start, finish;
    double duration;
    int e[1001][1001],k,i,j,n,temp;
    FILE* file;
    file = fopen(argv[1], "r");
    fread(&n, sizeof(int), 1, file);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            fread(&temp, sizeof(int), 1, file);
            e[i][j] = temp;
        }
    }
    fclose(file);
    for(k=1;k<=n;k++)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(e[i][j]>e[i][k]+e[k][j])
                    e[i][j]=e[i][k]+e[k][j];
            }
        }
    }
    finish = clock();
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            printf("%3d ",e[i][j]);
        }
        printf("\n");
    }
    //duration = (double)(finish - start) / CLOCKS_PER_SEC;
    //printf("%lf\n",duration);
    return 0;
}